package conf

import (
	"embed"
	"gopkg.in/ini.v1"
	"log"
)

var DatabaseConf DbConf

func InitDatabaseConfig(files embed.FS, section string) (DbConf, error) {
	//cfg, err := ini.Load("./static/conf/database.ini")
	file, err := files.ReadFile("static/conf/database.ini")

	var dbConfig DbConf

	cfg, err := ini.Load(file)
	if err != nil {
		log.Fatal(err)
		return dbConfig, err
	}
	//dbConf := new(conf.DatabaseConf)
	err = cfg.Section(section).MapTo(&dbConfig)
	if err != nil {
		log.Fatal(err)
		return dbConfig, err
	}
	return dbConfig, nil
}